﻿using System;
using System.Collections;
using System.Windows.Controls;
using jSLCore.Client.Presentation.Authorization;
using jSLCore.Client.Presentation.BaseControl;
using jSLCore.Client.Presentation.BaseControl.DialogMessage;

namespace jSLApp.Client.Forms
{
    public partial class ChangeRole : DialogControl
    {
        public ChangeRole()
        {
            InitializeComponent();
        }

        public override void OkClicked()
        {
            if(combo.SelectedValue==null)
            {
                ErrorBox.ShowDialog("Необходимо указать новую роль");
                return;
            }
            var item = combo.SelectedValue;
            
            InvokeDataSelected(item);
        }

        public override bool IsOkVisible
        {
            get { return true; }
        }

        public override bool IsStandartOkCancelEnabled
        {
            get { return true; }
        }

        public override bool AutoSize
        {
            get { return true; }
        }

        public override void LoadInitialData()
        {
            //if(Security.SecurityBinding.HasPermission(Permission.ChangeUserEx))
            {
               DoWork("Загрузка ролей",(sender, args) =>
                                           {
                                               args.Result = Communication.Proxy.GetAllRoles();
                                           },(o, eventArgs) =>
                                                                 {
                                                                     if(eventArgs.Error==null)
                                                                         combo.ItemsSource = (IEnumerable) eventArgs.Result;
                                                                 });
            }
            /*else
            {
                DoWork("Загрузка ролей", (sender, args) =>
                {
                    args.Result = true;//Communication.Proxy.GetAdministratorRoleAccess();
                }, (o, eventArgs) =>
                {
                    if (eventArgs.Error == null)
                        combo.ItemsSource = (IEnumerable)eventArgs.Result;
                });
            }*/
        }

        public override Control GetControlForInitialFocus()
        {
            return combo;
        }
    }
}
